
<script>
  document.addEventListener("DOMContentLoaded", function () {
    function adjustMargin() {
        let hypothesisSidebar = document.querySelector("hypothesis-sidebar");

        if (hypothesisSidebar) {
            document.body.style.marginRight = "15px"; // Shift content to avoid sidebar overlap
            document.body.style.transition = "margin-right 0.3s ease-in-out"; // Smooth effect
        } else {
            document.body.style.marginRight = "0px"; // Reset when sidebar is closed
        }
    }

    // Move Hypothesis menu to the left side (Optional)
    function moveHypothesisToLeft() {
        let hypothesisSidebar = document.querySelector("hypothesis-sidebar");

        if (hypothesisSidebar) {
            hypothesisSidebar.style.left = "0"; 
            hypothesisSidebar.style.right = "auto"; 
        }
    }

    // Watch for Hypothesis sidebar opening
    const observer = new MutationObserver(() => {
        adjustMargin();
        moveHypothesisToLeft(); // Remove this if you want the sidebar on the right
    });

    observer.observe(document.body, { childList: true, subtree: true });

    // Ensure margin resets when page loads
    window.addEventListener("load", adjustMargin);

    // Load Hypothesis script if not already loaded
    if (!document.getElementById("hypothesisScript")) {
        let script = document.createElement("script");
        script.src = "https://hypothes.is/embed.js";
        script.id = "hypothesisScript";
        script.async = true;
        document.body.appendChild(script);
    }
});
</script>